package com.salt.modules.sys.web;

import com.salt.common.json.AjaxJson;
import com.salt.common.utils.StringUtils;
import com.salt.core.persistence.Page;
import com.salt.core.web.BaseController;
import com.salt.modules.sys.entity.Industry;
import com.salt.modules.sys.service.IndustryService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description
 * @Author salt
 * @Date 2022/8/23
 * @Version 1.0.1
 */
@RestController
@AllArgsConstructor
@RequestMapping("sys/industry")
public class IndustryController extends BaseController {

    private final IndustryService industryService;

    @ModelAttribute("industry")
    public Industry get(@RequestParam(required = false) String id) {
        if (StringUtils.isNotBlank(id))
            return industryService.get(id);
        return new Industry();
    }

    @GetMapping("page")
    public AjaxJson page(Industry industry,
                         HttpServletRequest request, HttpServletResponse response) {
        Page<Industry> page = industryService.findPage(new Page<>(request, response), industry);
        return AjaxJson.success().put("page", page);
    }

    @GetMapping("list")
    public AjaxJson list(Industry industry) {
        List<Industry> list = industryService.findList(industry);
        return AjaxJson.success().put("list", list);
    }

    @PostMapping("save")
    public AjaxJson save(Industry industry) {
        industryService.save(industry);
        return AjaxJson.success("保存成功!");
    }

    @GetMapping("queryById")
    public AjaxJson queryById(Industry industry) {
        return AjaxJson.success().put("industry", industry);
    }

    @DeleteMapping("delete")
    public AjaxJson delete(Industry industry) {
        industryService.delete(industry);
        return AjaxJson.success("删除成功!");
    }

    @PostMapping("batchDelete")
    public AjaxJson batchDelete(String idsJson) {
        return industryService.batchDelete(idsJson);
    }





}
